<template>
  <px-form-item label="任务类型" prop="factoryAreaCode" :rules="[{ required: isRequired, message: '任务类型不能为空', trigger: 'change' }]">
    <px-select v-model="taskType" clearable filterable placeholder="请选择任务类型" style="width: 100%" @change="changeTaskSource">
      <px-option v-for="item in factoryAreaList" :key="item.id" :label="item.name" :value="item.value" />
    </px-select>
  </px-form-item>
</template>
<script setup lang="ts">
import { onMounted, watch, ref } from "vue";
import { queryDictData } from "@/api/common";

// 父级方法和值
const emits = defineEmits(["changeTaskSource"]);
const props = defineProps(["taskType", "isRequired"]);

const taskType = ref("");
const factoryAreaList = ref([]);

watch(
  () => props.taskType,
  val => {
    taskType.value = props.taskType;
  },
  { immediate: true }
);
onMounted(() => {
  queryTaskSourceSelect();
});
// 获取任务类型下拉列表
const queryTaskSourceSelect = async () => {
  const tempFactoryAreaList = await queryDictData({ typeCode: "ERC_CHECK_TASK_TYPE" });
  factoryAreaList.value = tempFactoryAreaList || [];
};
// 改变任务类型值，传值给父级并做改变
const changeTaskSource = () => {
  emits("changeTaskSource", taskType.value);
};
</script>
